<script language="javascript">
<!--
function upload(){
//当前值传递给父窗口的相关表单
if(document.s1.newpic.value!=""){
opener.document.myform.pic.value=document.s1.newpic.value; 
}
window.close();
}
-->
</script>

<?php 
set_time_limit(0); 
//define('ROOT',dirname(__FILE__).'/');
if($_GET["type"]=="link"){
	$picurl="../eWebEditor/uploadfile/";	
}else{ 
	$picurl="../js/";
}
if($_POST['submit']){ 
	foreach ($_FILES['upfile']['tmp_name'] as $k=>$v){ 
		$filename=$picurl.$_FILES['upfile']['name'][$k];
		//echo "filetype:".$_FILES['upfile']['type'][$k];
		//取得文件扩展名
		switch($_FILES['upfile']['type'][$k])   
		{     
			case     "image/pjpeg":     
			$fileextname     =     "jpg";     
			break;     
			case     "image/gif":     
			$fileextname     =     "gif";     
			break;     
			case     "image/x-png":     
			$fileextname     =     "png";     
			break;     
			case     "application/x-shockwave-flash":     
			$fileextname     =     "swf";     
			break;     
			case     "text/plain":     
			$fileextname     =     "txt";     
			break;     
			case     "application/msword":     
			$fileextname     =     "doc";     
			break;     
			case     "application/x-zip-compressed":     
			$fileextname     =     "zip";     
			break;     
		} 
		//echo "filepath:".$filename;
		$basename=$_FILES['upfile']['name'][$k];
		//echo "basename:".$basename;
		$newfile=substr($picurl.$_FILES['upfile']['name'][$k],2);
		$fileerror=$_FILES['error'][$k];
		$ext=strtolower(pathinfo($filename));
		//echo "ext:".$fileextname;
		if(strstr("jpg gif bmp",$fileextname)==true){
			//echo "文件类型正确".$ext[1];
			
			echo "文件路径：".$fileerror;
			if(file_exists($filename)){
				unlink($filename);
				//echo "文件存在，已删除！<br>";
			}		
			(!$_FILES['upfile']['type'][$k]=="jpeg" ||
			!$_FILES['upfile']['type'][$k]=="jpg" ||
			!$_FILES['upfile']['type'][$k]=="gif") ||
			!$v || 
			(
			!file_exists($picurl.$_FILES['upfile']['name'][$k]) 
			&& @getimagesize($v) 
			&& @move_uploaded_file($v,$picurl.$_FILES['upfile']['name'][$k]) 
			&& ($flag=1)
			&& print ('上传'.$_FILES['upfile']['name'][$k].'成功<br /><img src="'.$picurl.$_FILES['upfile']['name'][$k].'"  height="62"  width="66" />')
			 )|| 
			 print ('上传'.$_FILES['upfile']['name'][$k].'失败<br />'); 
		}else{
		//$v="";
		echo "<script>alert('文件类型,只能上传.jpg ，.gif ，.bmp 类型文件');</script>";
		//die("");
		}

	} 
} 
?> 

<html> 
<head> 
<title>上传</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<style type="text/css">body,td{font-family:tahoma,verdana,arial;font-size:11px;line-height:15px;background-color:white;color:#666666;margin-left:20px;} 
strong{font-size:12px;} 
a:link{color:#0066CC;} 
a:hover{color:#FF6600;} 
a:visited{color:#003366;} 
a:active{color:#9DCC00;} 
table.itable{} 
td.irows{height:20px;}</style> 
</head> 
<body> 
<center><form enctype="multipart/form-data" method="post" name="s1"> 
请选择上传图片文件：<input name="upfile[]" type="file" style="width:200;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="25"><br> 

<div id="upload"></div> <br><br>
<input type="submit" name="submit" value="上传" style="width:30;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="25"><br><br><br>
上传后图片地址：<input name="newpic" type="text" value="<?php if($flag==1 and $picurl=="../eWebEditor/uploadfile/") {echo $newfile;} else if($flag==1) {echo $basename;} ?>" size="40" readonly="readonly" > 
<br><br> 

<input type="submit" value="确定" name="submit"  onclick="upload()"/>
</form> 
</center> 
</body> 
</html>